/**
 * 
 */
package com.guo.hui.code;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @className SourceCode
 * @author zhengguohui
 * @description
 * @date 2018年7月19日
 */
public class SourceCode {

	public static void main(String[] args) throws UnsupportedEncodingException {

		Map<String, Object> map = new HashMap<>();
		Collections.synchronizedMap(map);
		Map<String, Object> map2 = new ConcurrentHashMap<>();
		// Map<String, Object> map1 = new Hashtable<>();
		map.put("aa", 12);
		System.out.println("97".hashCode());
		System.out.println("a".hashCode());

	}

	public void stringCode() {
		String ss = "dass1";
		System.out.println(ss.concat("s"));// 拼接字符串
		char[] chr = ss.toCharArray();// 转化为char数组
		System.out.println(ss.indexOf("a"));// 是否包含
		System.out.println(ss.endsWith("s"));// startsWith 字符串是否以指定的后缀 suffix 结束
		System.out.println(ss.substring(0, 2).length());// 截取字符串
		System.out.println(ss.contains("ss1s"));// 是否包含
		System.out.println(ss.length());// 字符串length方法 数组length属性
		System.out.println(ss.replace("ss", "am"));
		System.out.println(ss.toLowerCase());
		System.out.println(ss.intern());// 返回常量池中的字符串
		System.out.println(ss.contains("ss1s"));// 是否包含
		System.out.println(ss.split(","));
		// getBytes 相关方法可用于编码转换
		String tt = "";
		try {
			tt = new String(ss.getBytes(), "ISO-8859-1");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("tt:" + tt);
	}

	public void listCode() {
		List<String> list = new ArrayList<>();
		Collections.synchronizedList(list);
		// List<String> list1 = new LinkedList<>();
		// List<String> list2 = new Vector<>();
		list.add("12");
		list.add("13");
		list.add("15");
		list.add("16");
		list.add("18");
		list.add("19");
		// list.add(3, "15");// 指定位置增加元素
		// list.set(2, "11");// 更新指定位置元素
		System.out.println(list.size());
		System.out.println(list.indexOf("16"));
		System.out.println(list.lastIndexOf("15"));
		System.out.println(list.get(1));
		// System.out.println(list.set(2, "11"));
		System.out.println(list);
		List<String> listDemo = new ArrayList<>();
		listDemo.add("15");
		list.removeAll(listDemo);
		list.subList(1, 2);
		System.out.println(list);
		Collections.sort(list);
		Object[] str = list.toArray();
		Arrays.sort(str);
		System.out.println(str);
		String[] str1 = list.toArray(new String[] {});
		System.out.println(str1);
	}

}
